// app.js
// 按需导入 $http 对象
import { $http } from '@escook/request-miniprogram'
$http.beforeRequest = function (options) {
  let token = wx.getStorageSync('token')
  if (token) {
    options.header = {
      'Authorization': 'Bearer ' + token
    }
  }
}
// 将按需导入的 $http 挂载到 wx 顶级对象之上，方便全局调用
wx.$http = $http
$http.baseUrl = 'https://live-api.itheima.net'
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null,
    token: wx.getStorageSync('token'),
    avatar: '',
    nickName: ''
  }
})
